package com.spica.platform.accesslimit;

import com.spica.platform.accesslimit.interceptor.AccessLimitInterceptor;
import com.spica.platform.redis.repository.RedisRepository;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
@ConditionalOnClass(WebMvcConfigurer.class)
public class AccessLimitAutoConfigure implements WebMvcConfigurer {

	@Resource
	private RedisRepository redisRepository;

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(new AccessLimitInterceptor(redisRepository));
	}
}
